﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Fis.Win.Forms
{
    public partial class RateEditForm : EditForm
    {
        public RateEditForm()
        {
            InitializeComponent();
        }

        public override void InitializeViewUI()
        {

        }

        public override void InitializeBinding()
        {
            var d = ViewModel["viewData"] as DataTable;
            ViewModel["Action"] = ViewState.ToString();

            //新建初始化
            if (ViewState == Agile.Engine.View.ViewState.AddNew)
            {
                var r = d.Rows[0];
                r["FDATE"] = DateTime.Now;
                r["FRATE"] = 1;
            }


            Fis.Win.Utils.UIUtils.ClearBindings(layoutControl1);
            edCode.DataBindings.Add("EditValue", d, "FCODE");
            edName.DataBindings.Add("EditValue", d, "FNAME");
            edDate.DataBindings.Add("EditValue", d, "FDATE");
            edRate.DataBindings.Add("EditValue", d, "FRATE");

            if (d.Rows.Count > 0 && d.Rows[0]["FISBASE"].Equals(1))
            {
                edRate.Properties.ReadOnly = true;
            }
        }

        protected override void InitializeAfterSave()
        {

            ViewModel = ViewProvider.InitializeViewModel(null);
            InitializeBinding();
            //edCode.EditValue = string.Empty;
            //edCode.Focus();
            //edName.EditValue = string.Empty;
            //edRate.EditValue = 1;
        }

        protected override bool SaveProcess()
        {
            ///失败
            if (!ViewProvider.ExecuteUpdate(ViewModel))
            {
                return false;
            }

            Message = "保存成功";
            return true;
        }
    }
}
